#include <NTDDK.h>
//#include <wdm.h>

NTSTATUS DriverEntry (
    IN PDRIVER_OBJECT pDriverObject,
    IN PUNICODE_STRING pRegistryPath	);
VOID DriverUnload (IN PDRIVER_OBJECT pDriverObject);
#pragma alloc_text(init, DriverEntry)
#pragma alloc_text(page, DriverUnload)


static char *global_buf = NULL;
static UNICODE_STRING unicode_str;
static KSPIN_LOCK global_lock;

VOID DriverUnload (IN PDRIVER_OBJECT pDriverObject)
{
    if (global_buf)
        ExFreePoolWithTag(global_buf, 45678);
    global_buf = NULL;
    KdPrint(("chap5 : %s\n", __FUNCTION__));
}

NTSTATUS DriverEntry (
    IN PDRIVER_OBJECT pDriverObject,
    IN PUNICODE_STRING pRegistryPath	)
{
    KIRQL oldirq;
    
    global_buf = ExAllocatePoolWithTag(NonPagedPool, 4096, 45678);
    KdPrint(("chap5 : %s, global_buf = %p\n", __FUNCTION__, global_buf));
	pDriverObject->DriverUnload = DriverUnload;

    KeInitializeSpinLock(&global_lock);
    RtlInitUnicodeString(&unicode_str, L"UNICODE BUFFER");

    KeAcquireSpinLock(&global_lock, &oldirq);
    KdPrint(("try a unicode buf %S, oldirq = %d\n", unicode_str.Buffer, oldirq));
    KeReleaseSpinLock(&global_lock, oldirq);
    
    return STATUS_SUCCESS;
}




